name: Docs GitHub CI

on:
  pull_request:
    paths:
      - doc/**
      - src/pom.xml

env:
  MAVEN_OPTS: -Xmx1024m -Dmaven.wagon.httpconnectionManager.ttlSeconds=25 -Dmaven.wagon.http.retryHandler.count=3 -Dorg.slf4j.simpleLogger.showDateTime=true -Dorg.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss,SSS -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Dspotless.apply.skip=true

jobs:
  docs:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v4
    - name: Set up JDK 11
      uses: actions/setup-java@v3
      with:
        java-version: 11
        distribution: 'temurin'
    - name: Set up Maven
      uses: stCarolas/setup-maven@v4.5
      with:
        maven-version: 3.9.5
    - name: Setup python for docs
      uses: actions/setup-python@v4
      with:
        python-version: '3.x'
        cache: 'pip' # caching pip dependencies from requirements.txt below
    - name: Setup python pip requirements for building docs
      working-directory: doc/en
      run: |
        pip install -r requirements.txt
    - name: Build docs
      run: |
        mvn -B -ntp -f doc/en compile
    - name: Check index.html
      run: |
        if test ! -f doc/en/target/user/html/index.html; then
          echo sphinx-build did not generate user/html/index.html >&2
          exit 1
        fi

  docs-zhcn:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK 11
      uses: actions/setup-java@v3
      with:
        java-version: 11
        distribution: 'temurin'
    - name: Set up Maven
      uses: stCarolas/setup-maven@v4.5
      with:
        maven-version: 3.9.5
    - name: Setup python for docs
      uses: actions/setup-python@v4
      with:
        python-version: '3.x'
        cache: 'pip' # caching pip dependencies from requirements.txt below
    - name: Setup python pip requirements for building docs
      working-directory: doc/en
      run: |
        pip install -r requirements.txt
    - name: Build docs
      run: |
        mvn -B -ntp -f doc/zhCN compile
    - name: Check index.html
      run: |
        if test ! -f doc/zhCN/target/user/html/index.html; then
          echo sphinx-build did not generate user/html/index.html >&2
          exit 1
        fi
